﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Instrument;

namespace UI
{
    public partial class NewProduction : DevExpress.XtraEditors.XtraForm
    {
        public NewProduction()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if(txtEditModel.EditValue == null || txtEditOffset.EditValue == null || txtEditQulifiedValue.EditValue == null
                || txtEditRange.EditValue == null || txtEditResCount.EditValue == null)
            {
                MessageBox.Show("参数不全");
                return;
            }
            Production production = new Production();
            production.Model = (string)txtEditModel.EditValue;
            production.ResistanceCount = (int)txtEditResCount.EditValue;
            production.QualifiedResistance = Convert.ToDouble( txtEditQulifiedValue.EditValue);
            production.Range = Convert.ToDouble( txtEditRange.EditValue);
            production.AllowOffset = Convert.ToDouble( txtEditOffset.EditValue);
            if( DataBaseOperation.GetInstance().CreatMeasureTable(production) == false)
            {
                MessageBox.Show("操作失败");
                return;
            }
            if(DataBaseOperation.GetInstance().InsertProductionModel(production) == false)
            {
                DataBaseOperation.GetInstance().CreatMeasureTable(production);
            }
            Close();
        }
    }
}